﻿Public Class Contact

    Public Function Clone() As Contact
        Dim C As New Contact
        C.WorkFax = Me.WorkFax
        C.WorkPhone = Me.WorkPhone
        C.Category = ""
        C.Company = Me.Company
        C.Country = Me.Country
        C.Department = Me.Department
        C.MainEmail = Me.MainEmail
        C.FileAs = Me.FileAs
        C.FullName = Me.FullName
        C.HomePhone = Me.HomePhone
        C.ItemId = Me.ItemId
        C.JobTitle = Me.JobTitle
        C.Mobile = Me.Mobile
        C.ContactPhoto = Me.ContactPhoto
        C.Nikename = Me.Nikename
        C.WebPage = Me.WebPage
        Return C
    End Function


    Private _FirstName As String
    <NonJsonized()> Public Property FirstName() As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Private _LastName As String
    <NonJsonized()> Public Property LastName() As String
        Get
            Return _LastName
        End Get
        Set(ByVal value As String)
            _LastName = value
        End Set
    End Property

    Private _Middel As String
    <NonJsonized()> Public Property Middel() As String
        Get
            Return _Middel
        End Get
        Set(ByVal value As String)
            _Middel = value
        End Set
    End Property

    Private _Birthday As Nullable(Of Date)
    Public Property Birthday() As Nullable(Of Date)
        Get
            Return _Birthday
        End Get
        Set(ByVal value As Nullable(Of Date))
            _Birthday = value
        End Set
    End Property

    Private _HomeFax As String
    <NonJsonized()> Public Property HomeFax() As String
        Get
            Return _HomeFax
        End Get
        Set(ByVal value As String)
            _HomeFax = value
        End Set
    End Property

    Private _HomeStreet As String
    <NonJsonized()> Public Property HomeStreet() As String
        Get
            Return _HomeStreet
        End Get
        Set(ByVal value As String)
            _HomeStreet = value
        End Set
    End Property

    Private _HomeCity As String
    <NonJsonized()> Public Property HomeCity() As String
        Get
            Return _HomeCity
        End Get
        Set(ByVal value As String)
            _HomeCity = value
        End Set
    End Property

    Private _HomeState As String
    <NonJsonized()> Public Property HomeState() As String
        Get
            Return _HomeState
        End Get
        Set(ByVal value As String)
            _HomeState = value
        End Set
    End Property

    Private _HomeZip As String
    <NonJsonized()> Public Property HomeZip() As String
        Get
            Return _HomeZip
        End Get
        Set(ByVal value As String)
            _HomeZip = value
        End Set
    End Property

    Private _HomeCountry As String
    <NonJsonized()> Public Property HomeCountry() As String
        Get
            Return _HomeCountry
        End Get
        Set(ByVal value As String)
            _HomeCountry = value
        End Set
    End Property

    Private _WorkStreet As String
    <NonJsonized()> Public Property WorkStreet() As String
        Get
            Return _WorkStreet
        End Get
        Set(ByVal value As String)
            _WorkStreet = value
        End Set
    End Property

    Private _WorkCity As String
    <NonJsonized()> Public Property WorkCity() As String
        Get
            Return _WorkCity
        End Get
        Set(ByVal value As String)
            _WorkCity = value
        End Set
    End Property

    Private _WorkState As String
    <NonJsonized()> Public Property WorkState() As String
        Get
            Return _WorkState
        End Get
        Set(ByVal value As String)
            _WorkState = value
        End Set
    End Property

    Private _WorkZip As String
    <NonJsonized()> Public Property WorkZip() As String
        Get
            Return _WorkZip
        End Get
        Set(ByVal value As String)
            _WorkZip = value
        End Set
    End Property

    Private _WorkCountry As String
    <NonJsonized()> Public Property WorkCountry() As String
        Get
            Return _WorkCountry
        End Get
        Set(ByVal value As String)
            _WorkCountry = value
        End Set
    End Property

    Private _WorkEmail As String
    <NonJsonized()> Public Property WorkEmail() As String
        Get
            Return _WorkEmail
        End Get
        Set(ByVal value As String)
            _WorkEmail = value
        End Set
    End Property

    Private _IM As String
    Public Property IM() As String
        Get
            Return _IM
        End Get
        Set(ByVal value As String)
            _IM = value
        End Set
    End Property

    Private _Anniversary As Nullable(Of Date)
    Public Property Anniversary() As Nullable(Of Date)
        Get
            Return _Anniversary
        End Get
        Set(ByVal value As Nullable(Of Date))
            _Anniversary = value
        End Set
    End Property

    Private _Notes As String
    Public Property Notes() As String
        Get
            Return _Notes
        End Get
        Set(ByVal value As String)
            _Notes = value
        End Set
    End Property

    Private _WebPage As String
    Public Property WebPage() As String
        Get
            Return _WebPage
        End Get
        Set(ByVal value As String)
            _WebPage = value
        End Set
    End Property

    Private _Nikename As String
    Public Property Nikename() As String
        Get
            Return _Nikename
        End Get
        Set(ByVal value As String)
            _Nikename = value
        End Set
    End Property

    Private _ContactPhoto As String
    Public Property ContactPhoto() As String
        Get
            Return _ContactPhoto
        End Get
        Set(ByVal value As String)
            _ContactPhoto = value
        End Set
    End Property

    Public WriteOnly Property Picture() As System.Drawing.Image
        Set(ByVal value As System.Drawing.Image)
            If value Is Nothing Then
                Me.ContactPhoto = "images/nophoto.png"
            Else
                Me.ContactPhoto = "MOBIMIN-AJAX/OUTLOOK?T=1&action=contactphoto&itemId=" & Me.ItemId
            End If
        End Set
    End Property

    Private _ItemId As String
    Public Property ItemId() As String
        Get
            Return _ItemId
        End Get
        Set(ByVal value As String)
            _ItemId = value
        End Set
    End Property

    Private _FullName As String
    Public Property FullName() As String
        Get
            Return _FullName
        End Get
        Set(ByVal value As String)
            _FullName = value
        End Set
    End Property

    Private _Mobile As String
    Public Property Mobile() As String
        Get
            Return _Mobile
        End Get
        Set(ByVal value As String)
            _Mobile = value
        End Set
    End Property

    Private _JobTitle As String
    Public Property JobTitle() As String
        Get
            Return _JobTitle
        End Get
        Set(ByVal value As String)
            _JobTitle = value
        End Set
    End Property

    Private _Company As String
    Public Property Company() As String
        Get
            Return _Company
        End Get
        Set(ByVal value As String)
            _Company = value
        End Set
    End Property

    Private _FileAs As String
    Public Property FileAs() As String
        Get
            Return _FileAs
        End Get
        Set(ByVal value As String)
            _FileAs = value
        End Set
    End Property

    Private _Country As String
    Public Property Country() As String
        Get
            Return _Country
        End Get
        Set(ByVal value As String)
            _Country = value
        End Set
    End Property

    Private _Department As String
    Public Property Department() As String
        Get
            Return _Department
        End Get
        Set(ByVal value As String)
            _Department = value
        End Set
    End Property

    Private _WorkPhone As String
    Public Property WorkPhone() As String
        Get
            Return _WorkPhone
        End Get
        Set(ByVal value As String)
            _WorkPhone = value
        End Set
    End Property

    Private _WorkFax As String
    Public Property WorkFax() As String
        Get
            Return _WorkFax
        End Get
        Set(ByVal value As String)
            _WorkFax = value
        End Set
    End Property

    Private _HomePhone As String
    Public Property HomePhone() As String
        Get
            Return _HomePhone
        End Get
        Set(ByVal value As String)
            _HomePhone = value
        End Set
    End Property

    Private _MainEmail As String
    Public Property MainEmail() As String
        Get
            Return _MainEmail
        End Get
        Set(ByVal value As String)
            _MainEmail = value
        End Set
    End Property

    Private _Category As String
    Public Property Category() As String
        Get
            Return _Category
        End Get
        Set(ByVal value As String)
            _Category = value
        End Set
    End Property

End Class

Public Class Contacts

    Public Sub Flattern()
        Dim NewContacts As New List(Of Contact)
        For Each C In Me.Rows
            Dim Categories = C.Category.Split(",").ToList
            If Categories.Count > 1 Then
                C.Category = Categories.First
                For I As Integer = 1 To Categories.Count - 1
                    Dim NewContact = C.Clone
                    NewContact.Category = Categories(I).Trim
                    NewContacts.Add(NewContact)
                Next
            End If
        Next
        If NewContacts.Count > 0 Then
            Me.Rows.AddRange(NewContacts.AsEnumerable)
        End If
        'Me.rows = Me.rows.OrderBy(Of String)(Function(p) p.Category).ToList
    End Sub

    Public ReadOnly Property Results() As Long
        Get
            Return Me.Rows.Count
        End Get
    End Property

    Private _Success As Boolean
    Public Property Success() As Boolean
        Get
            Return _Success
        End Get
        Set(ByVal value As Boolean)
            _Success = value
        End Set
    End Property

    Private _Rows As List(Of Contact)
    Public Property Rows() As List(Of Contact)
        Get
            Return _Rows
        End Get
        Set(ByVal value As List(Of Contact))
            _Rows = value
        End Set
    End Property
End Class